var formatter; $(document).ready(function () { formatter = new Intl.NumberFormat('ru', { maximumFractionDigits: 0 }); var observer = new MutationObserver(function(mutations) { my_resize(); }); var timer_for_fix = false; observer.observe(document.body, { //document.body is node target to observe childList: true, subtree: true }); /* const resizeObserver = new ResizeObserver(async () => { await BX24.fitWindow(my_resize()); console.log('1', document.body.clientWidth); console.log('2', document.body.clientWidth); }); */ const resizeObserver = new ResizeObserver(() => { my_resize(); if(!timer_for_fix) { timer_for_fix = setTimeout(function(){ BX24.fitWindow(); timer_for_fix = false; //clearTimeout(timer_for_fix); }, 200); } }); /* Локализация datepicker */ $.datepicker.regional['ru'] = { closeText: 'Закрыть', prevText: 'Предыдущий', nextText: 'Следующий', currentText: 'Сегодня', timeOnlyTitle: 'Выберите время', timeText: 'Время', hourText: 'Часы', minuteText: 'Минуты', secondText: 'Секунды', monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'], monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн','Июл','Авг','Сен','Окт','Ноя','Дек'], dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'], dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'], dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'], weekHeader: 'Не', dateFormat: 'dd.mm.yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: '', millisecText: 'Миллисекунды', timezoneText: 'Часовой пояс', timeFormat: 'HH:mm', }; $.datepicker.setDefaults($.datepicker.regional['ru']); $.timepicker.setDefaults($.datepicker.regional['ru']); var myControl = { create: function(tp_inst, obj, unit, val, min, max, step){ $('') .appendTo(obj) .spinner({ min: min, max: max, step: step, change: function(e,ui){ if(e.originalEvent !== undefined) tp_inst._onTimeChange(); tp_inst._onSelectHandler(); }, spin: function(e,ui){ tp_inst.control.value(tp_inst, obj, unit, ui.value); tp_inst._onTimeChange(); tp_inst._onSelectHandler(); } }); return obj; }, options: function(tp_inst, obj, unit, opts, val){ if(typeof(opts) == 'string' && val !== undefined) return obj.find('.ui-timepicker-input').spinner(opts, val); return obj.find('.ui-timepicker-input').spinner(opts); }, value: function(tp_inst, obj, unit, val){ if(val !== undefined) return obj.find('.ui-timepicker-input').spinner('value', val); return obj.find('.ui-timepicker-input').spinner('value'); } }; $(document).on('change', '.js-user-multiple', function (e) { $('li.select2-selection__choice:has(.extranet-user)').addClass('TEMPORARY'); setTimeout(() => { $('li.select2-selection__choice:has(.extranet-user)').addClass('TEMPORARY'); }, 50); console.log('here'); }); $('textarea').each(function( key, elem ) { resizeObserver.observe(elem); }); $("input.datepicker").datepicker({ showOn: "button", buttonImage: "images/calendar-icon.gif", buttonImageOnly: true, buttonText: "Выбрать дату" }).on('show', function (ev) { my_resize(); }); $(document).on('click', 'img.ui-datepicker-trigger', function(e) { console.log('date resize'); my_resize(); }); $(document).on('click', '.close-icon', function(e) { var result = confirm('Удалить поставщика?') if(result) { $(this).closest('tr').remove(); $('.close-icon').each(function(index) { $(this).closest('tr').find('.row-num').html(index + 1); }); } }); $(document).on('click', '.popup-close', function(e) { let cur_modal = $(this).closest('.popup'); cur_modal.hide(); $('#overlay').hide(); }); $(document).on('click', 'a.add-from-crm', function(e) { $('#overlay').show(); $('#choose_provider').show(); }); $(document).on('input', 'input.num-input', function() { this.value = this.value.replace(/\D/g,''); if(isNaN(this.value) || this.value == '') this.value = 0; this.value = parseInt(this.value); }); $('form').on('input', '.data-num-to-buy input.num-input', function(event, is_manual) { this.value = this.value.replace(/\D/g,''); //if(isNaN(this.value) || this.value == '' || this.value < 0) if(isNaN(this.value) || this.value < 0) this.value = 0; else if(this.value == '') this.value = -1; this.value = parseInt(this.value); const min_val = $(this).data('min'); const max_val = $(this).data('max'); //let is_correct_lim = true; //инициализация if(this.value == -1) { if(!isNaN(min_val) && !isNaN(max_val)) { if(min_val > max_val) { this.value = parseInt(min_val); } else this.value = parseInt(max_val); } else this.value = 0; } else if(this.value != 0) { if(!isNaN(min_val)) { if(min_val > this.value) { this.value = parseInt(min_val); } } else this.value = 0; } let parent_row = $(this).closest('tr'); let provider_id = $(this).closest('td').data('provider_id'); if(provider_id >= 0) { let price = parseInt(parent_row.find('td.data-price[data-provider_id="' + provider_id + '"] input[name="price_for_calc"]').val().replace(/\D/g,'')); /* let num = parseInt(parent_row.find('td.data-num[data-provider_id="' + provider_id + '"] div').html().replace(/\D/g,'')); if(parent_row.find('td.data-is-lot-win[data-provider_id="' + provider_id + '"] input').is(':checked')) num = parseInt(this.value); */ let num = parseInt(this.value); if(1/* parent_row.find('td.data-is-lot-win[data-provider_id="' + provider_id + '"] input').is(':checked') */) { let vat = 1; if(parent_row.find('td.data-vat[data-provider_id="' + provider_id + '"] input[name="vat_included_for_calc"]').val() == 0) { vat = parseInt(parent_row.find('td.data-vat-rate[data-provider_id="' + provider_id + '"] input[name="vat_rate_for_calc"]').val().replace(/\D/g,'')); if(vat <= 0) vat = 1; else { vat = 1 + (vat / 100); vat = Math.round(vat * 100) / 100; } } let res = parseFloat(price * num * vat); if(isNaN(res) || res <= 0) res = 0; res = Math.round(res * 100) / 100; parent_row.find('td.data-sum[data-provider_id="' + provider_id + '"] div').html(formatter.format(Math.ceil(res))); let transport_price = parseInt($('input.transport_costs[data-provider_id="' + provider_id + '"]').val().replace(/\D/g,'')); if(isNaN(transport_price) || transport_price < 0) transport_price = 0; let new_sum = 0; let new_sum_with_transport = 0; let buf = $('tfoot td.itog[data-provider_id="' + provider_id + '"] span').data('old_val'); //if(typeof buf == 'string' && !isNaN(buf)) if(typeof buf == 'string') buf = buf.replace(/\D/g,''); let old_val = formatter.format(buf); buf = $('tfoot td.itog-plus-transport[data-provider_id="' + provider_id + '"] span').data('old_val'); //if(typeof buf == 'string' && !isNaN(buf)) if(typeof buf == 'string') buf = buf.replace(/\D/g,''); let old_val_with_transport = formatter.format(buf); let is_any_elem_counted = false; let position_num = $('td.data-sum[data-provider_id="' + provider_id + '"] div').length; for(let i = 0; i < position_num; i++) { let prod_elem = $($('td.data-sum[data-provider_id="' + provider_id + '"] div')[i]); new_sum += parseInt(prod_elem.html().replace(/\D/g,'')); let input_elem = $($('td.data-num-to-buy[data-provider_id="' + provider_id + '"] input')[i]); if(parseInt(input_elem.val()) > 0) is_any_elem_counted = true; } if(!is_any_elem_counted) transport_price = 0; new_sum_with_transport = formatter.format(Math.ceil(new_sum) + transport_price); new_sum = formatter.format(Math.ceil(new_sum)); if(old_val != new_sum) { $('tfoot td.itog[data-provider_id="' + provider_id + '"] s').html(old_val); $('tfoot td.itog[data-provider_id="' + provider_id + '"] span').html(new_sum); } else { $('tfoot td.itog[data-provider_id="' + provider_id + '"] s').html(''); $('tfoot td.itog[data-provider_id="' + provider_id + '"] span').html(new_sum); } if(old_val_with_transport != new_sum_with_transport) { $('tfoot td.itog-plus-transport[data-provider_id="' + provider_id + '"] s').html(old_val_with_transport); $('tfoot td.itog-plus-transport[data-provider_id="' + provider_id + '"] span').html(new_sum_with_transport); } else { $('tfoot td.itog-plus-transport[data-provider_id="' + provider_id + '"] s').html(''); $('tfoot td.itog-plus-transport[data-provider_id="' + provider_id + '"] span').html(new_sum_with_transport); } } } }); $('form').on('change', 'td.data-is-lot-win input', function(event, is_manual) { let parent_row = $(this).closest('tr'); let provider_id = $(this).closest('td').data('provider_id'); /* if($(this).is(':checked')) { parent_row.find('td.data-num-to-buy[data-provider_id="' + provider_id + '"] input.num-input').trigger('input'); } else { let old_val = $('tfoot td.itog[data-provider_id="' + provider_id + '"] span').data('old_val'); $('tfoot td.itog[data-provider_id="' + provider_id + '"] s').html(''); $('tfoot td.itog[data-provider_id="' + provider_id + '"] span').html(old_val); $('tfoot td.itog-plus-transport[data-provider_id="' + provider_id + '"] s').html(''); $('tfoot td.itog-plus-transport[data-provider_id="' + provider_id + '"] span').html(old_val); } */ parent_row.find('td.data-num-to-buy[data-provider_id="' + provider_id + '"] input.num-input').trigger('input'); }); $(document).on('click', 'a.row-comment-icon', function(e) { console.log($(this)); var rect = $(this)[0].getBoundingClientRect(); $('#comments-popup').css('top', Math.ceil(rect.top) + 'px'); $('#comments-popup').css('left', Math.ceil(rect.left) + 'px'); $('#comments-popup').find('.messages-area').remove(); const provider_id = $(this).closest('td').data('provider_id'); const row_ind = $(this).closest('tr').find('.item-number').data('item_id'); const ssp_id = $(this).data('ssp_id'); /* const one_data = all_data.find((element) => element.id === provider_id); */ const one_data = all_data[provider_id]; $('#comments-popup').find('form input[name="provider_id"]').val(provider_id); $('#comments-popup').find('form input[name="item_id"]').val(row_ind); $('#comments-popup').find('form input[name="ssp_id"]').val(ssp_id); //debugger; if(!!one_data.rows[row_ind]) { let comments_num = one_data.rows[row_ind]['comments'].length; if(comments_num > 0) { let comments_arr = one_data.rows[row_ind]['comments']; $('#comments-popup').find('.popup-body form').prepend('
'); for(let i = 0; i < comments_num; i++) { $('#comments-popup').find('div.messages-area').append('
' + comments_arr[i].date + '
' + comments_arr[i].author + '
' + comments_arr[i].text + '
'); } } } $('#overlay').show(); $('#comments-popup').show(); console.log(Math.ceil(rect.top), Math.ceil($('#comments-popup').outerHeight(true)), Math.ceil($('#comments-popup').outerHeight(true)) + Math.ceil(rect.top)); setTimeout(function(){ //my_resize(Math.ceil($('#comments-popup').outerHeight(true)) + Math.ceil(rect.top) + 40); BX24.fitWindow(); }, 200); //BX24.fitWindow(); return false; }); $(document).ready(function() { let indent = 20; let item_col_width = $('.col-fixed.item-number').outerWidth(); let name_col_width = $('.col-fixed.item-name').outerWidth(); let request_col_width = $('.col-fixed.item-request').outerWidth(); let measurement_col_width = $('.col-fixed.item-measurement').outerWidth(); $('.col-fixed.item-number').css('left', -1 * indent); $('.col-fixed.item-name').css('left', item_col_width); $('.col-fixed.item-name').css('left', item_col_width - indent); $('.col-fixed.item-request').css('left', item_col_width + name_col_width - indent); $('.col-fixed.item-measurement').css('left', item_col_width + name_col_width + request_col_width - indent); $('.col-fixed.item-comment').css('left', item_col_width + name_col_width + request_col_width + measurement_col_width - indent); $('td.data-num-to-buy input.num-input').trigger('input'); }); $(document).on('click', 'button.to-vote', function(e) { var result = confirm('После завершения голосования Вы не сможете изменить решение. Продолжить?'); if(result) { let flag = true; let checked_elems = $('input[name^="is_lot_win["]:checked'); let cloned_products_to_buy = JSON.parse(JSON.stringify(products_to_buy));//[...products_to_buy]; let problem_str = ''; for(let i = 0; i < checked_elems.length; i++) { const ssp_id = $(checked_elems[i]).data('ssp_id'); const num_input_elem = $('input[name="quantity[' + ssp_id + ']"]'); if(num_input_elem.length) { const val = parseInt(num_input_elem.val()); const spec_prod_id = parseInt(num_input_elem.data('spec_prod_id')); let prod_data = cloned_products_to_buy.find(el => el.spec_prod_id == spec_prod_id); if(!!prod_data) { prod_data.quantity = prod_data.quantity - val; } } } for(let i = 0; i < cloned_products_to_buy.length; i++) { if(cloned_products_to_buy[i].quantity > 0) problem_str += cloned_products_to_buy[i].name + '\n'; } //console.log(cloned_products_to_buy, 'cloned_products_to_buy'); //debugger; if(problem_str.length) { var result2 = confirm('Не все товарные позиции согласованны к закупке в необходимом количестве. Вы действительно хотите завершить голосование?\n\nПосле завершения голосования Вы не сможете изменить решение\n\nНедостаточное количество в позициях:\n\n' + problem_str); if(!result2) { return false; } } $('input[name="is_form_ok"]').val(1); return true; } return false; }); $('.single-select > select').select2({ dropdownPosition: 'below', "language": { "noResults": function(){ return "Не найдено"; }, "searching": function(){ return "Поиск..."; }, }, //minimumResultsForSearch: Infinity, cache: true, placeholder: 'Выбрать', //allowClear: true }); $('.multiple-select > select').select2({ dropdownPosition: 'below', "language": { "noResults": function(){ return "Не найдено"; }, "searching": function(){ return "Поиск..."; }, }, //minimumResultsForSearch: Infinity, cache: true, placeholder: 'Выбрать', //allowClear: true }); $('.card-field .slct-service select, .card-field .slct-good select').select2({ dropdownPosition: 'below', "language": { "noResults": function(){ return "Не найдено"; }, "searching": function(){ return "Поиск..."; }, }, //minimumResultsForSearch: Infinity, cache: true, placeholder: 'Выбрать', //allowClear: true }); my_resize(); $('td.data-is-lot-win input').trigger('change'); }); $(document).on('click', 'a.bx24-slider-link', function(e) { BX.SidePanel.Instance.open($(this).attr('href')); return false; }); function my_resize(fixed_height = 0) { let max_height = $('body').outerHeight(true) + 1; let width = document.body.clientWidth; if(fixed_height > 0) { max_height = fixed_height; } else { let test_val = 1; if($('#ui-datepicker-div:visible').length) { test_val = $('#ui-datepicker-div').position().top + $('#ui-datepicker-div').outerHeight(true) > $('body').outerHeight(true) ? $('#ui-datepicker-div').position().top + $('#ui-datepicker-div').outerHeight(true) : $('body').outerHeight(true); if(test_val > max_height) max_height = test_val; } test_val = 1; if ($('.select2-dropdown').length) { if($('body').outerHeight(true) < $('.select2-dropdown').outerHeight(true) + $('.select2-dropdown').offset().top) { test_val = $('.select2-dropdown').outerHeight(true) + $('.select2-dropdown').offset().top + 16; if(test_val > max_height) max_height = test_val; } } let rect = $('#comments-popup')[0].getBoundingClientRect(); test_val = Math.ceil(rect.bottom) + 30; if(test_val > max_height) { //BX24.resizeWindow(width + 10, max_height); //BX24.fitWindow(); //width = document.body.clientWidth; max_height = test_val; } } //console.log($('body').outerWidth(true) + $('body').scrollTop(), document.body.clientWidth); BX24.resizeWindow(width, max_height);//прокрутка не учитывается } function declension(num, entities_name = ['', '', '']) { let a = num; let str = ""; if (a / 10 >= 10) a = parseInt(a.toString().slice(-2)); if (a >= 5 && a <= 20) str = " " + entities_name[0]; else if (a % 10 == 1) str = " " + entities_name[1]; else if (a % 10 > 1 && a % 10 < 5) str = " " + entities_name[2]; else if (a % 10 >= 5 || a % 10 == 0) str = " " + entities_name[0]; return str; }